package springinpractice.ch8.news.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import springinpractice.ch8.news.model.NewsItem;
import springinpractice.common.dao.AbstractHibernateDao;

/*
 * Author       :       Willie Wheeler and John Wheeler
 * Book         :       'Spring In Practice' [Book written by Willie Wheeler and John Wheeler]
 */

@Repository("newsItemDao")
public class HbnNewsItemDao extends AbstractHibernateDao<NewsItem>
	implements NewsItemDao {

	@SuppressWarnings("unchecked")
	public List<NewsItem> getListByDateDesc(int maxResults) {
		Query q = getSession().createQuery(
				"select item from NewsItem item order by item.datePublished desc")
			.setMaxResults(maxResults);
		return (List<NewsItem>) q.list();
	}
}
